package com.revenant.driver.ui.activity;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.apkfuns.logutils.LogUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.revenant.driver.R;
import com.revenant.driver.adapter.EmptyNoLoginItemAdapter;
import com.revenant.driver.base.BaseActivity;
import com.revenant.driver.bean.ShipperBean.EmptyCarNoLoginBean;
import com.revenant.driver.utils.GsonUtil;
import com.revenant.driver.utils.SPUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.revenant.driver.utils.Constants.List_Empty_No_Login;

public class NoIdentificationActivity extends BaseActivity {


    @BindView(R.id.left_base)
    ImageView leftBase;
    @BindView(R.id.right_base)
    ImageView rightBase;
    @BindView(R.id.basetitle_show_or_hide)
    LinearLayout basetitleShowOrHide;
    @BindView(R.id.nologinrecyclerview)
    RecyclerView nologinrecyclerview;
    @BindView(R.id.nologinpublishbotton)
    FloatingActionButton nologinpublishbotton;
    private EmptyNoLoginItemAdapter itemAdapter;
    private Context context;

    private int loginType = 0;
//    private int pagernum = 1;
    /*  0未登录，1，登录未验证，2验证  */


    @Override
    public int getContentViewResId() {
        context = this;
        return R.layout.activity_noidentification;
    }

    @Override
    public void initView() {
        String a = SPUtils.getUserToken(context);
//        String b = SPUtils.getUserAuthentication(context);
        String jpRidToken = SPUtils.getJpRidToken(context);
//        LogUtils.d("AAAAAAAAAA" + a + b + jpRidToken);
        if (SPUtils.getUserToken(context).isEmpty()) {
            loginType = 0;
        }
//        else if (SPUtils.getUserAuthentication(context).equals("0")) {
//            loginType = 1;
//        }
        itemAdapter = new EmptyNoLoginItemAdapter();
        nologinrecyclerview.setAdapter(itemAdapter);
        nologinrecyclerview.setLayoutManager(new LinearLayoutManager(context));
        itemAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
//                getLogin();
            }
        });

        itemAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                switch (view.getId()) {
                    case R.id.nologinphone:
//                        getLogin();
                        break;
                    default:
                }
            }
        });


    }

    @Override
    protected boolean isshowtitlebar() {
        return false;

    }

    @Override
    public void initData() {
        if (loginType == 0 || loginType == 1) {
            getNologinData();
        }
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.left_base, R.id.right_base, R.id.nologinpublishbotton})
    public void onViewClickedId(View view) {
        switch (view.getId()) {
            case R.id.left_base:
                if (loginType == 0) {
                    getLogin();
                } else {
                    startActivity(MineShipperActivity.class);
                }
//                startActivity(LoginActivity.class);
//                startActivity(MineDriverActivity.class);
//                getMine(MineShipperActivity.class);
//                startActivity(MineShipperActivity.class);

//                startActivity(MineDriverActivity.class);
//                startActivity(TemplateActivity.class);
//                startActivity(MineReceiptActivity.class);
//                startActivity(DriverTrackActivity.class);
                break;
            case R.id.right_base:
                if (loginType == 0) {
                    getLogin();
                } else if (loginType == 1) {
                    getauthentication();
                }
//                getLogin(NewsActivity.class);
//                startActivity(NewsActivity.class);
                break;
            case R.id.nologinpublishbotton:

                if (loginType == 0) {
                    getLogin();
                } else if(loginType == 1){
                    getauthentication();
                }

//                getLogin();
//                Utils.callPhone(this, "15881354454");
//                startActivity(LoginActivity.class);
                break;
        }
    }

    private void getNologinData() {
        OkGo.<String>get(List_Empty_No_Login)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LogUtils.d("AAAAAAAAAAAAA"+response.body());
                        EmptyCarNoLoginBean s = GsonUtil.parseJsonWithGson(response.body(), EmptyCarNoLoginBean.class);
                        if (s.getCode().equals("0")) {
                            itemAdapter.setNewData(s.getData());
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                    }
                });
    }

    public void getLogin() {
        if (SPUtils.getUserToken(context).isEmpty()) {
            showToast("请先登录");
            startActivity(LoginActivity.class);
        }
    }


    public void getMine() {
        if (SPUtils.getUserToken(context).isEmpty()) {
            showToast("请先登录");
            startActivity(LoginActivity.class);
        }
    }


    public void getauthentication() {
//        if (SPUtils.getUserAuthentication(context).equals("0")) {
//            showToast("请先认证");
//            startActivity(NewSecondImproveDriverInformationActivity.class);
//        }
    }

    private void getauth() {
//        OkGo.<String>get(List_Empty_No_Authentication)
//
//                .params("isAuthentication", "1")
//                .params("pageNum", pagernum)
//                .execute(new StringCallback() {
//                    @Override
//                    public void onSuccess(Response<String> response) {
//                    }
//
//                    @Override
//                    public void onFinish() {
//                        super.onFinish();
//                    }
//                });
//    }}
    }
}
